<?php 
	//timer pengecekan load page...
	include("timer.php");
	$_start_timer = get_microtime();

	require_once("protect1.php"); 
	require_once("connect.php");
	require_once("settings.php");

	// $pilih=mysql_select_db("uwika_krs",$conn);
	$pdo->query("USE uwika_krs");

	//ganti dengan yg otomatis
	$_select_semester = $_GET["sel_smt"];
	$_select_periode = $_global_settings['tahun_ajaran']->value;

	//protect2 
	//kalau lambat, bisa dihapus
	//cheking semester.. biar gk aneh2 mbukak.. prevent from sql injection
	$sql = "SELECT distinct semester FROM penawaran WHERE semester = :semester AND jurusan = :jurusan ORDER BY semester LIMIT 1";
	$stmt = $pdo->prepare($sql);
	$stmt->execute(array(':semester' => $_select_semester
						,':jurusan' => $reg_jurusan));
	$row = $stmt->fetch(PDO::FETCH_OBJ);
	if(empty($row->semester)){
		//manual input.. g onok matakuliah coy...
		$host  = $_SERVER['HTTP_HOST'];
		$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
		$extra = 'studentpage.php';
		header("Location: http://$host$uri/$extra");
		?>
			<meta http-equiv="refresh" content="0; url=studentpage.php">
			Klik <a href="studentpage.php">disini</a> apabila browser anda berhenti berjalan ...
		<?php
		exit;
	}
?>
<STYLE type=text/css>.blank {
	FONT-SIZE: 0px; WIDTH: 0px; HEIGHT: 0px
}
TD {
	FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
INPUT {
	FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
.present {
	FONT-WEIGHT: bold; BACKGROUND-COLOR: #dee5ec
}
.h1 {
	FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: #ffffff
}
.d1 {
	COLOR: #c0c0c0
}
.link {
	FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none
}
.footer {
	FONT-WEIGHT: normal; FONT-SIZE: 10px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none
}
.footer1 {
	FONT-WEIGHT: bold; FONT-SIZE: 10px; BACKGROUND-IMAGE: url(chat/images/menu_b.gif); CURSOR: default; COLOR: #000000; BORDER-BOTTOM: 0px
}
.header {
	FONT-WEIGHT: bold; FONT-SIZE: 10px; BACKGROUND-IMAGE: url(chat/images/menu_h.gif); CURSOR: default; COLOR: #000000; BORDER-BOTTOM: 0px
}
.textcol {
	FONT-SIZE: 12px; COLOR: #2378d5; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11pt;
	color: #FFFFFF;
}
body {
	background-color: #001E8C;
	background-image: url(bg.jpg);
	background-repeat: repeat;
}
a:link {
	color: #FFFFFF;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #FFFFFF;
}
a:hover {
	text-decoration: underline;
	color: #001D86;
}
a:active {
	text-decoration: none;
	color: #001C8A;
}
</STYLE>


<title>:: Daftar Kuliah ::</title><table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="7e96dc">&nbsp;</td>
  </tr>
  <tr>
    <td><img src="images/bannerAtas.jpg" alt="image" width="780" height="200" /></td>
  </tr>
  <tr>
    <td bgcolor="3a5db1">
		<BR>
		Berikut dibawah ini adalah daftar mata kuliah yang ditawarkan pada :
		<br>
		Semester : <?php echo $_select_semester; ?>
		<br>
		Periode &nbsp&nbsp : <?php echo $_select_periode; ?>
		<table width="100%" border=0>
		<tr><td width=5%></td><td>
		<table align=center width=100% border="0">
		<tr bgcolor="#001E8C"><td width=5%><center><b>H A R I</b></center></td>
		<td width=12%><center><b>P U K U L</b></center></td>
		<td width=5%><center><b>K O D E</b></center></td>
		<td width=25%><center><b>N A M A &nbsp; M A T A  &nbsp; K U L I A H</b></center></td>
		<td width=5%><center><b>SKS</b></center></td></b>
		</tr>
		<br />
	<?php
	
	$_hari = array('SENIN', 'SELASA','RABU', 'KAMIS','JUMAT','SABTU','BEBAS');

	$sql = "SELECT recno, penawaran.kodemk, nama, sks, dosen, keterangan, pagu, sesi, hari, mulaipukul, selesaipukul 
			FROM penawaran , mk WHERE semester = :select_semester and periode = :select_periode 
			and penawaran.kodemk = mk.kodemk and hari = :hari 
			and jurusan = :reg_jurusan order by mulaipukul";
	$stmt = $pdo->prepare($sql);

	$table_colour = 0;
	$print_hari = true;
	
	for($i = 0; $i < count($_hari); $i++ ){
		$stmt->execute(array(':select_semester' => $_select_semester
							,':select_periode' => $_select_periode
							,':hari' => $_hari[$i]
							,':reg_jurusan' => $reg_jurusan )); //reg jurusan dari protect1.php

		if($stmt->rowCount() > 0){
			while($_data = $stmt->fetch(PDO::FETCH_OBJ)){ //fetch data to stdclass object
				?>
					<tr bgcolor="<?php if(($table_colour % 2) == 0){ echo "#7e96dc"; } else { echo "#4585cd"; }?>">
						<td><center><?php if($print_hari){ echo $_hari[$i]; $print_hari = false; }?></center></td>
						<td><center><?php echo $_data->mulaipukul." - ".$_data->selesaipukul; ?></center></td>
						<td><center>
							<?php 
								//echo '<a href="daftar.php?recno='.$_data->recno.'&kodemk='.$_data->kodemk.'&sesi='.$_data->sesi.'&periode='.$_select_periode.'&semester='.$_select_semester.'">';
								//still using recno for double data
								echo '<a href="daftar.php?recno='.$_data->recno.'&kodemk='.$_data->kodemk.'">';
								echo $_data->kodemk; 
								echo '</a></center></td>';
							?>							
						<td><?php echo $_data->nama; ?></td>
						<td><center><?php echo $_data->sks; ?></center></td>
					</tr>
				<?php
			}
			$table_colour++;
			$print_hari = true;
		}
	}
	
	?>
		</table><td width=5%></td></tr></table>
		<br>
		*) Klik pada kode mata kuliah untuk mendaftar ...
		<BR><BR>

	<?php
	$sql = "SELECT sks,ips,toleransi FROM ips WHERE nrp=:reg_uname LIMIT 1";
	$stmt = $pdo->prepare($sql);
	$stmt->execute(array(':reg_uname' => $reg_uname ));

	$_data = $stmt->fetch(PDO::FETCH_OBJ);
	//	list($sks,$ips,$toleransi) = $row;

	$sql ="SELECT SUM(sks) AS sksdlmkrs FROM registrasi WHERE nrp=:reg_uname LIMIT 1";
	$stmt = $pdo->prepare($sql);
	$stmt->execute(array(':reg_uname' => $reg_uname ));

	$_data2 = $stmt->fetch(PDO::FETCH_OBJ);
	// list($sksdlmkrs) = $row;

	if ($_data->ips < 1.500) {
		$limitsksx = 12;
	}
	if (($_data->ips >= 1.500) and ($_data->ips < 1.750)) {
		$limitsksx = 14;
	}
	if (($_data->ips >= 1.750) and ($_data->ips < 2.000)) {
		$limitsksx = 16;
	}
	if (($_data->ips >= 2.000) and ($_data->ips < 2.250)) {
		$limitsksx = 18;
	}
	if (($_data->ips >= 2.250) and ($_data->ips < 3.000)) {
		$limitsksx = 21;
	}
	if ($_data->ips >= 3.000) {
		$limitsksx = 24;
	}
	?>
		<table width="90%">
		<tr><td width=5%></td>
		<td><table width="90%">
	<?php
	$sql="SELECT biodata.nama FROM security,biodata where security.username = :reg_uname AND biodata.nrp = security.username";
	$stmt = $pdo->prepare($sql);
	$stmt->execute(array(':reg_uname' => $reg_uname ));
	$_data3 = $stmt->fetch(PDO::FETCH_OBJ);
	
	// list($namamhs) = $row;
	/*
		mengubah disini YULIUS H
		untuk siswa angkatan baru agar tidak 12 SKS
	*/

	$pengecekan = $reg_uname[3].$reg_uname[4];
	if ($pengecekan == 12)
	{
		$limitsksx = 24;
	}
	// Sampai disini saja!
	
	?>
		<tr><td width=20%>N R P</td><td>:</td><td width=83%><?php echo $reg_uname; ?></td></tr>
		<tr><td width=20%>N A M A</td><td>:</td><td width=83%><?php echo $_data3->namamhs; ?></td></tr>
		<tr><td width=20%>Nilai IPS terakhir </td><td>:</td><td width=83%><?php echo $_data->ips; ?></td></tr>
		<tr><td>Limit SKS anda</td><td>:</td><td><?php echo $limitsksx; ?> SKS</td></tr>
		<tr><td>Toleransi SKS anda</td><td>:</td><td><?php echo $_data->toleransi ?> SKS</td></tr>
		<tr><td>Sisa Limit SKS anda</td><td>:</td><td><?php echo $limitsksx + $_data->toleransi - $_data2->sksdlmkrs; ?> SKS</td></tr>
		</table><td width=5%></td></tr></table>
		<br>
	<?php
	
	include("footer.php");

	/*
	
	//SENIN
	$sqlstr = "select penawaran.recno, penawaran.kodemk, $matakuliah.nama, $matakuliah.sks, penawaran.dosen, penawaran.keterangan, penawaran.pagu, penawaran.sesi,penawaran.hari,penawaran.mulaipukul,penawaran.selesaipukul from penawaran,$matakuliah where semester='$_select_semester' and periode='$_select_periode' and penawaran.kodemk=$matakuliah.kodemk and penawaran.hari='SENIN' and penawaran.jurusan=$reg_jurusan order by penawaran.mulaipukul";
	$hasil = mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	$counter=1;
	do {
		list($recno,$kodemk,$nama,$sks,$dosen,$keterangan,$pagu,$sesi,$hari,$mulaipukul,$selesaipukul) = $row;
		if (empty($kodemk)) {
		echo "<BR><BR>";
		break;
		} 
		if ($counter==1) {
			echo "<tr bgcolor=\"#4585cd\"><td><center>$hari</center></td>";
		} else
			echo "<tr bgcolor=\"#4585cd\"><td><center></center></td>";
		echo "<td><center>$mulaipukul - $selesaipukul</center></td>";
		echo "<td><center><a href=\"daftar.php?recno=$recno&kodemk=$kodemk&sesi=$sesi&periode=$_select_periode&semester=$_select_semester\"> $kodemk </center></td>";
		echo "<td> $nama </td>";
		echo "<td><center> $sks </center></td>";
		echo "</tr>";
		$counter = $counter + 1;
	} while ($row=mysql_fetch_row($hasil));

	//SELASA
	$sqlstr="select penawaran.recno, penawaran.kodemk, $matakuliah.nama, $matakuliah.sks, penawaran.dosen, penawaran.keterangan, penawaran.pagu, penawaran.sesi,penawaran.hari,penawaran.mulaipukul,penawaran.selesaipukul from penawaran,$matakuliah where semester='$_select_semester' and periode='$_select_periode' and penawaran.kodemk=$matakuliah.kodemk and penawaran.hari='SELASA' and penawaran.jurusan=$reg_jurusan order by penawaran.mulaipukul";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	$counter=1;
	do {
		list($recno,$kodemk,$nama,$sks,$dosen,$keterangan,$pagu,$sesi,$hari,$mulaipukul,$selesaipukul) = $row;
		if (empty($kodemk)) {
		echo "<BR><BR>";
		break;
		} 
		if ($counter==1) {
			echo "<tr bgcolor=\"#7e96dc\"><td><center>$hari</center></td>";
		} else
			echo "<tr bgcolor=\"#7e96dc\"><td><center></center></td>";
		echo "<td><center>$mulaipukul - $selesaipukul</center></td>";
		echo "<td><center><a href=\"daftar.php?recno=$recno&kodemk=$kodemk&sesi=$sesi&periode=$_select_periode&semester=$_select_semester\"> $kodemk </center></td>";
		echo "<td> $nama </td>";
		echo "<td><center> $sks </center></td>";
		echo "</tr>";
		$counter = $counter + 1;
	} while ($row=mysql_fetch_row($hasil));

	//RABU
	$sqlstr="select penawaran.recno, penawaran.kodemk, $matakuliah.nama, $matakuliah.sks, penawaran.dosen, penawaran.keterangan, penawaran.pagu, penawaran.sesi,penawaran.hari,penawaran.mulaipukul,penawaran.selesaipukul from penawaran,$matakuliah where semester='$_select_semester' and periode='$_select_periode' and penawaran.kodemk=$matakuliah.kodemk and penawaran.hari='RABU' and penawaran.jurusan=$reg_jurusan order by penawaran.mulaipukul";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	$counter=1;
	do {
		list($recno,$kodemk,$nama,$sks,$dosen,$keterangan,$pagu,$sesi,$hari,$mulaipukul,$selesaipukul) = $row;
		if (empty($kodemk)) {
		echo "<BR><BR>";
		break;
		} 
		if ($counter==1) {
			echo "<tr bgcolor=\"#4585cd\"><td><center>$hari</center></td>";
		} else
			echo "<tr bgcolor=\"#4585cd\"><td><center></center></td>";
		echo "<td><center>$mulaipukul - $selesaipukul</center></td>";
		echo "<td><center><a href=\"daftar.php?recno=$recno&kodemk=$kodemk&sesi=$sesi&periode=$_select_periode&semester=$_select_semester\"> $kodemk </center></td>";
		echo "<td> $nama </td>";
		echo "<td><center> $sks </center></td>";
		echo "</tr>";
		$counter = $counter + 1;
	} while ($row=mysql_fetch_row($hasil));

	//KAMIS
	$sqlstr="select penawaran.recno, penawaran.kodemk, $matakuliah.nama, $matakuliah.sks, penawaran.dosen, penawaran.keterangan, penawaran.pagu, penawaran.sesi,penawaran.hari,penawaran.mulaipukul,penawaran.selesaipukul from penawaran,$matakuliah where semester='$_select_semester' and periode='$_select_periode' and penawaran.kodemk=$matakuliah.kodemk and penawaran.hari='KAMIS' and penawaran.jurusan=$reg_jurusan order by penawaran.mulaipukul";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	$counter=1;
	do {
		list($recno,$kodemk,$nama,$sks,$dosen,$keterangan,$pagu,$sesi,$hari,$mulaipukul,$selesaipukul) = $row;
		if (empty($kodemk)) {
		echo "<BR><BR>";
		break;
		} 
		if ($counter==1) {
			echo "<tr bgcolor=\"#7e96dc\"><td><center>$hari</center></td>";
		} else
			echo "<tr bgcolor=\"#7e96dc\"><td><center></center></td>";
		echo "<td><center>$mulaipukul - $selesaipukul</center></td>";
		echo "<td><center><a href=\"daftar.php?recno=$recno&kodemk=$kodemk&sesi=$sesi&periode=$_select_periode&semester=$_select_semester\"> $kodemk </center></td>";
		echo "<td> $nama </td>";
		echo "<td><center> $sks </center></td>";
		echo "</tr>";
		$counter = $counter + 1;
	} while ($row=mysql_fetch_row($hasil));

	//JUMAT
	$sqlstr="select penawaran.recno, penawaran.kodemk, $matakuliah.nama, $matakuliah.sks, penawaran.dosen, penawaran.keterangan, penawaran.pagu, penawaran.sesi,penawaran.hari,penawaran.mulaipukul,penawaran.selesaipukul from penawaran,$matakuliah where semester='$_select_semester' and periode='$_select_periode' and penawaran.kodemk=$matakuliah.kodemk and penawaran.hari='JUMAT' and penawaran.jurusan=$reg_jurusan order by penawaran.mulaipukul";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	$counter=1;
	do {
		list($recno,$kodemk,$nama,$sks,$dosen,$keterangan,$pagu,$sesi,$hari,$mulaipukul,$selesaipukul) = $row;
		if (empty($kodemk)) {
		echo "<BR><BR>";
		break;
		} 
		if ($counter==1) {
			echo "<tr bgcolor=\"#4585cd\"><td><center>$hari</center></td>";
		} else
			echo "<tr bgcolor=\"#4585cd\"><td><center></center></td>";
		echo "<td><center>$mulaipukul - $selesaipukul</center></td>";
		echo "<td><center><a href=\"daftar.php?recno=$recno&kodemk=$kodemk&sesi=$sesi&periode=$_select_periode&semester=$_select_semester\"> $kodemk </center></td>";
		echo "<td> $nama </td>";
		echo "<td><center> $sks </center></td>";
		echo "</tr>";
		$counter = $counter + 1;
	} while ($row=mysql_fetch_row($hasil));

	//SABTU
	$sqlstr="select penawaran.recno, penawaran.kodemk, $matakuliah.nama, $matakuliah.sks, penawaran.dosen, penawaran.keterangan, penawaran.pagu, penawaran.sesi,penawaran.hari,penawaran.mulaipukul,penawaran.selesaipukul from penawaran,$matakuliah where semester='$_select_semester' and periode='$_select_periode' and penawaran.kodemk=$matakuliah.kodemk and penawaran.hari='SABTU' and penawaran.jurusan=$reg_jurusan order by penawaran.mulaipukul";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	$counter=1;
	do {
		list($recno,$kodemk,$nama,$sks,$dosen,$keterangan,$pagu,$sesi,$hari,$mulaipukul,$selesaipukul) = $row;
		if (empty($kodemk)) {
		echo "<BR><BR>";
		break;
		} 
		if ($counter==1) {
			echo "<tr bgcolor=\"#7e96dc\"><td><center>$hari</center></td>";
		} else
			echo "<tr bgcolor=\"#7e96dc\"><td><center></center></td>";
		echo "<td><center>$mulaipukul - $selesaipukul</center></td>";
		echo "<td><center><a href=\"daftar.php?recno=$recno&kodemk=$kodemk&sesi=$sesi&periode=$_select_periode&semester=$_select_semester\"> $kodemk </center></td>";
		echo "<td> $nama </td>";
		echo "<td><center> $sks </center></td>";
		echo "</tr>";
		$counter = $counter + 1;
	} while ($row=mysql_fetch_row($hasil));

	//BEBAS
	$sqlstr="select penawaran.recno, penawaran.kodemk, $matakuliah.nama, $matakuliah.sks, penawaran.dosen, penawaran.keterangan, penawaran.pagu, penawaran.sesi,penawaran.hari,penawaran.mulaipukul,penawaran.selesaipukul from penawaran,$matakuliah where semester='$_select_semester' and periode='$_select_periode' and penawaran.kodemk=$matakuliah.kodemk and penawaran.hari='BEBAS' and penawaran.jurusan=$reg_jurusan order by penawaran.mulaipukul";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	$counter=1;
	do {
		list($recno,$kodemk,$nama,$sks,$dosen,$keterangan,$pagu,$sesi,$hari,$mulaipukul,$selesaipukul) = $row;
		if (empty($kodemk)) {
		echo "<BR><BR>";
		break;
		} 
		if ($counter==1) {
			echo "<tr bgcolor=\"#4585cd\"><td><center>$hari</center></td>";
		} else
			echo "<tr bgcolor=\"#4585cd\"><td><center></center></td>";
		echo "<td><center>$mulaipukul - $selesaipukul</center></td>";
		echo "<td><center><a href=\"daftar.php?recno=$recno&kodemk=$kodemk&sesi=$sesi&periode=$_select_periode&semester=$_select_semester\"> $kodemk </center></td>";
		echo "<td> $nama </td>";
		echo "<td><center> $sks </center></td>";
		echo "</tr>";
		$counter = $counter + 1;
	} while ($row=mysql_fetch_row($hasil));

	
	echo "</table><td width=5%></td></tr></table>";
	echo "<br>";
	echo "*) Klik pada kode mata kuliah untuk mendaftar ...";
	echo "&nbsp;";
	echo "<BR><BR>";
	$sqlstr="select sks,ips,toleransi from ips where nrp='$reg_uname'";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	list($sks,$ips,$toleransi) = $row;
	$sqlstr="select sum(sks) from registrasi where nrp='$reg_uname'";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	list($sksdlmkrs) = $row;
	if ($ips < 1.500) {
		$limitsksx = 12;
	}
	if (($ips >= 1.500) and ($ips < 1.750)) {
		$limitsksx = 14;
	}
	if (($ips >= 1.750) and ($ips < 2.000)) {
		$limitsksx = 16;
	}
	if (($ips >= 2.000) and ($ips < 2.250)) {
		$limitsksx = 18;
	}
	if (($ips >= 2.250) and ($ips < 3.000)) {
		$limitsksx = 21;
	}
	if ($ips >= 3.000) {
		$limitsksx = 24;
	}
	echo "<table width=\"90%\">";
	echo "<tr><td width=5%></td>";
	echo "<td><table width=\"90%\">";
	$sqlstr="SELECT biodata.nama FROM security,biodata where security.username='$reg_uname' and biodata.nrp=security.username";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	list($namamhs) = $row;

		//mengubah disini YULIUS H
		//untuk siswa angkatan baru agar tidak 12 SKS

	$pengecekan = $reg_uname[3] . $reg_uname[4];
	if ($pengecekan == 12)
	{
		$limitsksx = 24;
	}
	// Sampai disini saja!
	echo "<tr><td width=20%>N R P</td><td>:</td><td width=83%>$reg_uname</td></tr>";
	echo "<tr><td width=20%>N A M A</td><td>:</td><td width=83%>$namamhs</td></tr>";
	echo "<tr><td width=20%>Nilai IPS terakhir </td><td>:</td><td width=83%>$ips</td></tr>";
	echo "<tr><td>Limit SKS anda</td><td>:</td><td>$limitsksx SKS</td></tr>";
	echo "<tr><td>Toleransi SKS anda</td><td>:</td><td>$toleransi SKS</td></tr>";
	echo "<tr><td>Sisa Limit SKS anda</td><td>:</td><td>";
	echo $limitsksx+$toleransi-$sksdlmkrs;
	echo " SKS</td></tr>";
	echo "</table><td width=5%></td></tr></table>";
	echo "<br>";
	*/
?>
	&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="7e96dc"><div align="center">
	<footer id="main">
	  <a href="http://www.widyakartika.ac.id/perpustakaan">Perpustakaan Online</a> | <a href="http://krs.widyakartika.ac.id/">KRS Online</a>
	  <br \>
	  Copyright &copy; 2012. <a href="http://www.widyakartika.ac.id">Universitas Widya Kartika</a> & <a href="#">Labkom ICT</a> - All rights reserved
	  <p>
		<?php
			$_finish_timer = get_microtime();
			echo 'Page generated in '.round(($_finish_timer - $_start_timer), 4).' seconds.';
		?>
	</footer>
	</div></td>
  </tr>
</table>
